package com.heima.article.controller;

import com.heima.article.service.ApAuthorService;
import com.heima.common.enums.AppHttpCodeEnum;
import com.heima.common.exception.LeadException;
import com.heima.model.article.dtos.AuthorDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 作者相关
 */
@RestController
@RequestMapping("/api/v1/author")
public class AuthorController {

    @Autowired
    private ApAuthorService apAuthorService;

    /**
     * 新增作者
     */
    @PostMapping("/save")
    public Integer save(@RequestBody AuthorDto authorDto){
        return apAuthorService.saveAuthor(authorDto);
    }

    /**
     * 通过用户id查询作者
     */
    @GetMapping("/findByApUserId/{apUserId}")
    public AuthorDto findByApUserId(@PathVariable("apUserId") Integer apUserId){
        AuthorDto authorDto = apAuthorService.findByApUserId(apUserId);
        if (authorDto==null){
            throw new LeadException(AppHttpCodeEnum.DATA_NOT_EXIST);
        }
        return authorDto;
    }

























}
